// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License.
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
// All other rights reserved.

//*******************************************************************************************
// Enhancements created by Kyle Bilenki
// March 28th 2010
// - Added ability to limit Date Selection to Future Dates only
// - Added ability to limit Date Selection to Past Dates only
// - Added ability to limit Date Selection to a range
// April 1st 2010
// - Enhanced set_earliestSelectibleDate function to accept either a String or a Date Object
// - Enhanced set_latestSelectibleDate function to accept either a String or a Date Object
// April 3rd 2010
// - Enhanced the "Today's Date" button to respect Earliest and Latest Date selectible range (if defined)
// April 5th 2010
// - Corrected a defect which caused the Dispose JS function to throw an exception when the Today's Date element had
//   no event handler(s).
// - Begun work on Selectible Dates being sourced from a Web Service call.  
//*******************************************************************************************

using System;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.ComponentModel;
using System.ComponentModel.Design;
using AjaxControlToolkit;

[assembly: System.Web.UI.WebResource("KSharp.AjaxControlToolkit.CalendarExtenderMk2.CalendarBehaviorMk2.js", "text/javascript")]
[assembly: System.Web.UI.WebResource("KSharp.AjaxControlToolkit.CalendarExtenderMk2.CalendarMk2.css", "text/css", 
                                     PerformSubstitution = true)]
[assembly: System.Web.UI.WebResource("KSharp.AjaxControlToolkit.CalendarExtenderMk2.arrow-left.gif", "image/gif")]
[assembly: System.Web.UI.WebResource("KSharp.AjaxControlToolkit.CalendarExtenderMk2.arrow-right.gif", "image/gif")]

namespace KSharp.AjaxControlToolkit
{
    [Designer("KSharp.AjaxControlToolkit.CalendarExtenderMk2.CalendarMk2Designer, KSharp.AjaxControlToolkit")]
    [RequiredScript(typeof(CommonToolkitScripts), 0)]
    [RequiredScript(typeof(DateTimeScripts), 1)]
    [RequiredScript(typeof(PopupExtender), 2)]
    [RequiredScript(typeof(AnimationScripts), 3)]
    [RequiredScript(typeof(ThreadingScripts), 4)]
    [TargetControlType(typeof(TextBox))]
    [ClientCssResource("KSharp.AjaxControlToolkit.CalendarExtenderMk2.CalendarMk2.css")]
    [ClientScriptResource("KSharp.AjaxControlToolkit.CalendarBehaviorMk2", 
                          "KSharp.AjaxControlToolkit.CalendarExtenderMk2.CalendarBehaviorMk2.js")]
    [System.Drawing.ToolboxBitmap(typeof(CalendarExtenderMk2), "KSharp.AjaxControlToolkit.CalendarExtenderMk2.Calendar.ico")]
    public class CalendarExtenderMk2 : ExtenderControlBase
    {
        [DefaultValue("")]
        [ExtenderControlProperty]
        [ClientPropertyName("cssClass")]
        public virtual string CssClass
        {
            get { return GetPropertyValue("CssClass", string.Empty); }
            set { SetPropertyValue("CssClass", value); }
        }

        [DefaultValue("yyyy/mm/dd")]
        [ExtenderControlProperty]
        [ClientPropertyName("format")]
        public virtual string Format
        {
            get { return GetPropertyValue("Format", "d"); }
            set { SetPropertyValue("Format", value); }
        }

        [DefaultValue(true)]
        [ExtenderControlProperty]
        [ClientPropertyName("enabled")]
        public virtual bool EnabledOnClient
        {
            get { return GetPropertyValue("EnabledOnClient", true); }
            set { SetPropertyValue("EnabledOnClient", value); }
        }

        [DefaultValue(true)]
        [ExtenderControlProperty]
        [ClientPropertyName("animated")]
        public virtual bool Animated
        {
            get { return GetPropertyValue("Animated", true); }
            set { SetPropertyValue("Animated", value); }
        }

        [DefaultValue(FirstDayOfWeek.Default)]
        [ExtenderControlProperty]
        [ClientPropertyName("firstDayOfWeek")]
        public virtual FirstDayOfWeek FirstDayOfWeek
        {
            get { return GetPropertyValue("FirstDayOfWeek", FirstDayOfWeek.Default); }
            set { SetPropertyValue("FirstDayOfWeek", value); }
        }

        [DefaultValue("")]
        [ExtenderControlProperty]
        [ClientPropertyName("button")]
        [ElementReference]
        [IDReferenceProperty]
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", 
                                                         "CA1706:ShortAcronymsShouldBeUppercase", 
                                                         Justification = "Following ASP.NET AJAX pattern")]
        public virtual string PopupButtonID
        {
            get { return GetPropertyValue("PopupButtonID", string.Empty); }
            set { SetPropertyValue("PopupButtonID", value); }
        }        
        
        [ExtenderControlProperty]
        [ClientPropertyName("popupPosition")]
        [DefaultValue(CalendarMk2Position.BottomLeft)]
        [Description("Indicates where you want the calendar displayed, bottom or top of the textbox.")]
        public virtual CalendarMk2Position PopupPosition
        {
            get { return GetPropertyValue("PopupPosition", CalendarMk2Position.BottomLeft); }
            set { SetPropertyValue("PopupPosition", value); }
        }

        [ExtenderControlProperty]
        [ClientPropertyName("selectibleDates")]
        [DefaultValue(CalendarMk2SelectibleDates.All)]
        [Description("Indicates the type of selectible dates should be allowed by the Calendar Control")]
        public virtual CalendarMk2SelectibleDates SelectibleDates
        {
            get { return GetPropertyValue("SelectibleDates", CalendarMk2SelectibleDates.All); }
            set { SetPropertyValue("SelectibleDates", value); }
        }

        [ExtenderControlProperty]
        [ClientPropertyName("earliestSelectibleDate")]
        [DefaultValue(null)]
        [Description("Indicates the earliest date that is allowed to be selected by the calendar control")]
        public virtual Nullable<DateTime> EarliestSelectibleDate
        {
            get { return GetPropertyValue<Nullable<DateTime>>("EarliestSelectibleDate", new Nullable<DateTime>()); }
            set { SetPropertyValue<Nullable<DateTime>>("EarliestSelectibleDate", value); }
        }

        [ExtenderControlProperty]
        [ClientPropertyName("latestSelectibleDate")]
        [DefaultValue(null)]
        [Description("Indicates the latest date that is allowed to be selected by the calendar control")]
        public virtual Nullable<DateTime> LatestSelectibleDate
        {
            get { return GetPropertyValue<Nullable<DateTime>>("LatestSelectibleDate", new Nullable<DateTime>()); }
            set { SetPropertyValue<Nullable<DateTime>>("LatestSelectibleDate", value); }
        }

        [DefaultValue(null)]
        [ExtenderControlProperty]
        [ClientPropertyName("selectedDate")]
        public Nullable<DateTime> SelectedDate
        {
            get { return GetPropertyValue<DateTime?>("SelectedDate", null); }
            set { SetPropertyValue<DateTime?>("SelectedDate", value); }
        }

        [DefaultValue("")]
        [ExtenderControlEvent]
        [ClientPropertyName("showing")]
        public virtual string OnClientShowing
        {
            get { return GetPropertyValue("OnClientShowing", string.Empty); }
            set { SetPropertyValue("OnClientShowing", value); }
        }

        [DefaultValue("")]
        [ExtenderControlEvent]
        [ClientPropertyName("shown")]
        public virtual string OnClientShown
        {
            get { return GetPropertyValue("OnClientShown", string.Empty); }
            set { SetPropertyValue("OnClientShown", value); }
        }

        [DefaultValue("")]
        [ExtenderControlEvent]
        [ClientPropertyName("hiding")]
        public virtual string OnClientHiding
        {
            get { return GetPropertyValue("OnClientHiding", string.Empty); }
            set { SetPropertyValue("OnClientHiding", value); }
        }

        [DefaultValue("")]
        [ExtenderControlEvent]
        [ClientPropertyName("hidden")]
        public virtual string OnClientHidden
        {
            get { return GetPropertyValue("OnClientHidden", string.Empty); }
            set { SetPropertyValue("OnClientHidden", value); }
        }

        [DefaultValue("")]
        [ExtenderControlEvent]
        [ClientPropertyName("dateSelectionChanged")]
        public virtual string OnClientDateSelectionChanged
        {
            get { return GetPropertyValue("OnClientDateSelectionChanged", string.Empty); }
            set { SetPropertyValue("OnClientDateSelectionChanged", value); }
        }
    }
}